
<!DOCTYPE html>
<html lang="en">

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<meta http-equiv="X-UA-Compatible" content="ie=edge">
		<title>华胜后台管理</title>
		<link rel="stylesheet" type="text/css" href="css/unified.css">
		<script src="plugins/layui/layui.js"></script>
	</head>
	<body>

		<div class="kit-doc">
			<!-- 标题 -->
			<div class="kit-doc-title">
				<fieldset>
					<legend>
						<a name="blockquote"> 订单</a><span class="titles">前台下单  后台管理</span>
					</legend>
				</fieldset>
			</div>
			<!-- 标题 end-->

			<!-- 概述 -->
			<div class="boderbox">
				<!--  <div class="icon-title">
	                <i class="iconfont icon-Summary"></i>概述
	            </div> -->
				<div class="layui-tab">
					<ul class="layui-tab-title" id="orderhead">
						<li class="layui-this" >待付款</li>
						<li>待审核</li>
						<li>待发货</li>
						<li>待收货</li>
						<li>已完成</li>
						<li>未评价</li>
						<li>全部</li>
					</ul>

					<!--<form class="layui-form searchform searchform-a" action="" id="orderSearchForm">
						<select name="city" lay-verify="">
							<option value="oderid">订单号</option>
							<option value="name">会员名</option>
							<option value="region">收货地区</option>
						</select>
						<div class="layui-input-inline">
							<input type="text" name="text" required lay-verify="required" placeholder="输入关键字" autocomplete="off" class="layui-input">
						</div>
						<div class="layui-btn-group">
							<button class="layui-btn">搜索</button>
							<button class="layui-btn layui-btn-normal">高级筛选</button>
						</div>
					</form>-->
					<div class="layui-tab-content">
						<!-- 待付款 -->
						<div class="layui-tab-item layui-show">
							<table class="layui-table " lay-filter="table100" id="order1" ></table>
						</div>
						<!-- 待付款 end -->
						
						<!-- 待审核 -->
						<div class="layui-tab-item">
							<table class="layui-table " lay-filter="table100" id="order2"></table>
						</div>
						

						<!-- 待发货 -->
						<div class="layui-tab-item">
							<table class="layui-table " lay-filter="table100" id="order3"></table>
						</div>
						<!-- 待发货 end -->

						<!-- 待收货 -->
						<div class="layui-tab-item">
							<table class="layui-table " lay-filter="table100" id="order4"></table>
						</div>
						<!-- 待收货 end -->

						<!-- 已完成 -->
						<div class="layui-tab-item">
							<table class="layui-table " lay-filter="table100" id="order5"></table>
						</div>
						<!-- 已完成 end -->

						<!-- 未评价 -->
						<div class="layui-tab-item">
							<table class="layui-table " lay-filter="table100" id="order6"></table>
						</div>
						<!-- 未评价 end -->

						<!-- 全部 -->
						<div class="layui-tab-item">
							<table class="layui-table " lay-filter="table100" id="order7"></table>
						</div>
						<!-- 全部 end -->

					</div>
				</div>
				<script id="openbox" type="text/html">
					<table class="layui-table " lay-filter="table100" id="opensee"  lay-skin="row"  lay-even  >
						<thead><tr><td>状态</td><td>商品编号</td><td>商品条码</td><td>商品标题</td><td>购买数量</td><td>库存数量</td></tr></thead>
						<tbody></tbody>
					</table>
				</script>
				<script src="js/jquery-3.2.1.min.js"></script>
				<script type="text/javascript" src="js/allajax.js"></script>

				<script>
					//注意：选项卡 依赖 element 模块，否则无法进行功能性操作
var datafirst = "'sorting':'generate_time','tosort':'desc'"; //默认前缀data字符串
							var data1 = "{"+datafirst +",'paymentState':'PendingPay'}"; //待付款
							var data2 = "{"+datafirst +",'paymentState':'Success','orderState':'waitAudit'}"; //待审核
							
							var data3 = "{"+datafirst +",'paymentState':'Success','orderState':'Waiting_for_delivery  '}"; //等待发货
							var data4 = "{"+datafirst +",'paymentState':'Success','orderState':'Already_shipped'}" ;
							var data5 = "{"+datafirst +",'paymentState':'Success','orderState':'Complete'}";
							var data6 = "{"+datafirst +",'paymentState':'Success','orderState':'Complete','evaluation_state':'0'}";
							var data7 = "{"+datafirst+"}";
							var curr = 1;
							var limit = 100; 
							var thisindex = 1 ;
							var thtable = [ //基础信息数组
//								{field: 'seize',width: 100,title: '占位'},
								
								{field: 'orderNumber',width: 180,title: '订单号'},
//								{field: 'orderId',minWidth: '0%', width: '0%',type: 'space',style: 'display:none'},
//								{field: 'userId',minWidth: '0%', width: '0%',type: 'space',style: 'display:none'},
								{field: 'orderAddress',width: 400,title: '订单地址'},
								{field: 'contactName',width: 200,title: '收货人'},
								{field: 'contactPhone',width: 100,title: '收货人手机'},
								{field: 'contactTelephone',width: 180,title: '联系电话'},
								{field: 'paymentAmount',width: 100,title: '金额'},
								{field: 'orderRemarks',width: 100,title: '订单备注'}
								
							];
							//待付款
							var thtable1 = thtable.concat(); //全部
							thtable1.unshift(
//								{field: 'Cancelbtn',width: 150,title: '操作',fixed: 'true'},
								{type:'numbers',fixed: 'left',title: '行号'},
								{field: 'orderNumber',width: 180,title: '订单号'},
								{field: 'generateTime',width: 200,title: '生成时间'},
								{field: 'paymentMethod',width: 150,title: '付款方式'},
								{field: 'paymentState',width: 150,title: '付款状态'}
							); 
							
							//待审核
							var thtable2 = thtable.concat(); //全部
							thtable2.unshift(
//								{field: 'Cancelbtn',width: 150,title: '操作',fixed: 'true'},
								{type:'numbers',fixed: 'left',title: '行号'},
								{field: 'waitAudit',width: 150,title: '操作',fixed: 'true'},
								
							); 
							
							
							//待发货
							var thtable3 = thtable.concat(); //全部
							thtable3.unshift(
								{type:'numbers',fixed: 'left',title: '行号'},
								{field: 'operation',width: 100,title: '操作',fixed: 'true'},
							
							
							
//								{field: 'paymentMethod',width: 100,title: '付款方式'},
//								{field: 'paymentState',width: 100,title: '付款状态'}
							); 
							
							//待收货
							var thtable4 = thtable.concat(); //全部
							thtable4.unshift(
								{type:'numbers',fixed: 'left',title: '行号'},
								{field: 'expressNumber',width: 200,title: '快递单号'},
								{field: 'shippingMethod',width: 100,title: '装运方式'},
								{field: 'generateTime',width: 200,title: '生成时间'}
							)
							
							//已完成
							var thtable5 = thtable.concat(); //全部
							thtable5.push(
								{type:'numbers',fixed: 'left',title: '行号'},
								{field: 'paymentMethod',width: 100,title: '付款方式'},
								{field: 'paymentState',width: 100,title: '付款状态'},
								{field: 'shippingMethod',width: 100,title: '装运方式'},
								{field: 'expressNumber',width: 100,title: '快递单号'},
								{field: 'expressBusiness',width: 100,title: '订单备注'},
								{field: 'generateTime',width: 100,title: '生成时间'},
								{field: 'invoiceType',width: 100,title: '发票类型'},
								{field: 'invoiceHeader',width: 100,title: '发票抬头'},
								{field: 'deliveryNumber',width: 100,title: '交货编码'},
								{field: 'orderMachineIp',width: 100,title: '订单ip'},
								{field: 'deviceInfo',width: 100,title: '设备信息'},
								{field: 'tradeType',width: 100,title: '贸易类型'},
								{field: 'transactionId',width: 100,title: '交易id'},
								{field: 'orderType',width: 100,title: '订单类型'},
								{field: 'scoreUse',width: 100,title: '积分使用'},
								{field: 'orderProcess',width: 100,title: '订单审核'},
								{field: 'orderPickupCode',width: 100,title: '订单拾取编码'},
								{field: 'merchantNumber',width: 100,title: '店主编号'},
								{field: 'evaluationState',width: 100,title: '评价状态'},
								{field: 'wechatRefundResult',width: 100,title: '微信退款结果'},
							); 
							//全部
							var thtable0 = thtable.concat(); //全部
							thtable0.push(
								{type:'numbers',fixed: 'left',title: '行号'},
								{field: 'orderState',width: 100,title: '订单状态'},
								{field: 'paymentState',width: 100,title: '付款状态'}
								
//								{field: 'operation',width: 100,title: '操作' ,fixed: 'right'}
							); //付款状态 Unfinished 未完成 PendingPay待付款 Abnormal异常 Success 成功  Complete 订单完成
										




					layui.use(['layer', 'form', 'element', 'table', 'laydate','laypage'], function() {
						var layer = layui.layer,
							form = layui.form,
							element = layui.element,
							table = layui.table,
							laydate = layui.laydate,laypage = layui.laypage;
									
							productList(data1 , 1 , thtable1, curr ,limit , function(){
								productList(data2 , 2 , thtable2, curr ,limit , function(){
									productList(data3, 3 , thtable3, curr ,limit , function(){
										productList(data4 , 4 , thtable4, curr ,limit , function(){
											productList(data5 , 5 , thtable5, curr ,limit , function(){
												productList(data6 , 6 , thtable5, curr ,limit,function(){
													productList(data7 ,7 , thtable5, curr ,limit);
												});
											});
										});
									});
								});
							});
							
//							var Parameterdata = "{'sorting':'generate_time','tosort':'desc','payment_state':'success','order_process':'Waiting_for_delivery'}" ;
//							
//							localStorage.setItem('orderParameter',Parameterdata)
//							localStorage.setItem('orderParameter1',JSON.stringify( thtable1))
//							
//						productList("{'sorting':'generate_time','tosort':'desc'}");
						
						function productList(data , type , tablejson , curr , limit , callback){

							
							var tableArray = new Array();
							AjaxPostFn('system/orderinfo/select?page='+curr+'&pagesize='+limit, data, function(jsonData) {
								
								if(jsonData.pageInfo.size != 0){
									
								
	//								console.log(jsonData)
									$.each(jsonData.pageInfo.list, function(i, objjson) {
										obj = objjson.orderInfoWithBLOB;
//										Vos = objjson.orderCommodityVos[0];
										
//										ForSales = objjson.bizCommodityForSales[0];
//console.log(JSON.stringify(objjson.orderCommodityVos))
										tableArray.push({
											"Cancelbtn":'<a class="layui-btn " lay-event="CancelThis" >取消订单</a>',
											'operation': '<a class="layui-btn " lay-event="selectThis" >查看</a>',
											'waitAudit': '<a class="layui-btn " lay-event="waitAudit" >确认审核通过</a>',
											'Deliverbtn': '<a class="layui-btn " lay-event="DeliverThis" >发货</a>',
											
											"orderNumber": obj.orderNumber, //出库
								            "orderId": obj.orderId,
								            "userId": obj.userId,
								            "openid": obj.openid,
								            "orderAddress": obj.orderAddress,
								            "orderAdcode": obj.orderAdcode,
								            "contactName": obj.contactName,
								            "contactPhone": obj.contactPhone,
								            "contactTelephone": obj.contactTelephone,
								            "shippingMethod": obj.shippingMethod,
								            "orderState": obj.orderState,
								            "paymentMethod": obj.paymentMethod,
								            "paymentAmount": ( obj.paymentAmount /100).toFixed(2),
								            "paymentState": obj.paymentState,
								            "expressNumber": obj.expressNumber,
								            "expressBusiness": obj.expressBusiness,
								            "orderRemarks": obj.orderRemarks,
								            "generateTime": getMyDate(obj.generateTime),
								            "invoiceType": obj.invoiceType,
								            "invoiceHeader": obj.invoiceHeader,
								            "deliveryNumber": obj.deliveryNumber,
								            "orderMachineIp": obj.orderMachineIp,
								            "deviceInfo": obj.deviceInfo,
								            "tradeType": obj.tradeType,
								            "transactionId": obj.transactionId,
								            "paySuccessTime": obj.paySuccessTime,
								            "orderType": obj.orderType,
								            "scoreUse": obj.scoreUse,
								            "orderProcess": obj.orderProcess,
								            "orderPickupCode": obj.orderPickupCode,
								            "merchantNumber": obj.merchantNumber,
								            "evaluationState": obj.evaluationState,
								            "wechatPayResult": obj.wechatPayResult,
								            "wechatRefundResult": obj.wechatRefundResult,
								            "orderCommodityVos": objjson.orderCommodityVos ,
								            "bizCommodityForSales":objjson.bizCommodityForSales
//								            "barCode":ForSales.barCode,//出库条码
//								            "theNum":Vos.buyAmount,//出库订单商品数量
//								            "commodityId":ForSales.commodityId, //出库商品id
//								            "commodityNumber":ForSales.commodityNumber //出库商品编码
								            
								            
										});
										
		
									})
								}
//								console.log(tableArray)
	
								//展示已知数据
//							for(var i = 1 ; i < 8 ; i++){
								table.render({
									elem: '#order' + type,
									cols: [
										tablejson
									],
									data: tableArray,
									size: 'lg',
									even: true,
									
									page: true, //是否显示分页
									height: 'full-250',
									done: function(res, curr, count){
//										laypage.render({
//										    elem: 'layui-table-page'+type //注意，这里的 test1 是 ID，不用加 # 号
//										    ,count: jsonData.pageInfo.total//数据总数，从服务端得到
//										    
//										    ,jump: function(obj, first){
//											    //obj包含了当前分页的所有参数，比如：
////											    console.log(obj.curr); //得到当前页，以便向服务端请求对应页的数据。
////											    console.log(obj.limit); //得到每页显示的条数
//											   
//											    //首次不执行
//											    if(!first){
//											      //do something
//											  
//											       productList(data , type , tablejson , obj.curr , obj.limit )
//											    }
//											  }
//										  });
									}
									
								});
//							}
							table.on('tool(table100)', function(obj) {
								var data = obj.data;
								
								if(obj.event === 'selectThis') {
									//查看订单下的产品库存情况
									layer.open({
										type:1
									  	,skin: 'layui-layer-molv'
							          	,title: '查看订单号:'+data.orderNumber+' 订单'
							          	,maxmin: 'true'
							          	,shade: 0
							          	,area: ['80%' , '80%']
							         	,content:$("#openbox").html()
							          	,skin: 'demo-class'
							          	,btn:["确认发货","关闭"]
							          	,yes:function(index,layero){
							          	  //按钮1的回调
							         
										console.log(JSON.stringify(data));
										$.each(data.orderCommodityVos, function(voidx,voobj) {
							          	  var ForSales  = data.bizCommodityForSales[voidx];
							          	  var insertjson = '{  "orderNumber": "'+data.orderNumber+'", "barCode": "'+ForSales.barCode+'", "theNum": '+voobj.buyAmount+', "locationId": 1, "status": 0,"createId": 1, "createTime": "'+new Date().getTime()+'", "commodityNumber": "'+ForSales.commodityNumber+'", "merchantNumber": 1, "commodityId": "'+ForSales.commodityId+'"}   ';
							          	  
								          	AjaxPostFn('system/repository/prepare/insert', insertjson, function(data1 ) {
												if	(data1.htmlState.status == 200){
													layer.msg("订单出货成功");
													console.log(obj)
													obj.del();
													setTimeout(function(){
														layer.closeAll();
													},500)
													
													AjaxPostFn('system/orderinfo/examine/newexamine', "{'orderNumber':'"+obj.data.orderNumber+"','orderStatus':'Already_shipped'}", function(data) {
														if	(data.htmlState.status == 200){
															
														}
													})
													
													productList(data4 , 4 , thtable4, curr ,limit , function(){
														productList(data7 ,7 , thtable5, curr ,limit);
													})
													
													
													
												}
								          	},obj)
							          	})
							          	},btn2:function(index,layero){
							          	  //按钮2的回调
							          	},cancel:function(){
							           	 //右上关闭的回调
							          	},success:function(){
							          		//渲染商品数据
							          		console.log(data.orderCommodityVos) 
											var vostr ;
											$.each(data.orderCommodityVos, function(voidx,voobj) {
//												console.log(data.bizCommodityForSales.commodityId)
												vostr += "<tr><td>等待出库</td><td>"+voobj.commodityNumber+"</td>" +
														 "<td>"+data.bizCommodityForSales[voidx].barCode+"</td>" +
														 "<td>"+data.bizCommodityForSales[voidx].title+"</td>" +
														 "<td>"+voobj.buyAmount+"</td>" +
														 "<td></td></tr>";
											});
											
											
											$("#opensee tbody").html(vostr);
											
											
											
										}
							          	
											
									});
//							          		AjaxPostFn('system/orderinfo/select', {'orderNumber':data.orderNumber}, function(jsonData) {
////							          		console.log(jsonData);
//							          			
//							          			$(".openTable").html(jsonData)
//							          		})
							      
								}else if(obj.event === 'DeliverThis'){
									
									var delivejson = data;
									
									delivejson.locationId=0;
									delivejson.status = 1;
									delivejson.createId = 1
									delivejson.createTime =  getnowtime();
									console.log(JSON.stringify(delivejson))
									AjaxPostFn('system/repository/prepare/insert', JSON.stringify(delivejson), function(jsonData) {
//										 "orderNumber": 593209232, 订单号
//					                    "barCode": "654646456456",产品条形码
//					                    "theNum": '3333',准备货品数量
//					                    "locationId": 0,准备货品出库点
//					                    "status": 1,是否已发货
//					                    "createId": 1,备货人
//					                    "createTime": 1508150658000, 配货时间
//					                    "commodityNumber": 1506563373914, 商品编码
//					                    "merchantNumber": 123, 
//					                    "commodityId": null 商品i
										console.log(jsonData);
									
					          			
					          			
					          	});
								}else if(obj.event === 'waitAudit'){
										obj.del();
									AjaxPostFn('system/orderinfo/examine/newexamine', "{'orderNumber':'"+data.orderNumber+"','orderStatus':'Waiting_for_delivery'}", function(data) {
									if	(data.htmlState.status == 200){
										layer.msg("订单审核成功");
										
										productList(data3, 3 , thtable3, curr ,limit , function(){
											productList(data7 ,7 , thtable5, curr ,limit);
										})
									}
									})
								}
							})
							
						
							
							if(callback){
								callback();
							}
							
							
								
//								var active = {
//									selectThis:function(){
//										layer.open({
//											
//										  skin: 'layui-layer-molv'
//								          ,title: '查看订单'
//								          ,area: ['720px', '500px']
//								          ,content:$("#openbox").html()
//								          ,skin: 'demo-class'
//								          ,btn:["修改","关闭"]
//								          ,yes:function(index,layero){
//								            //按钮1的回调
//								          },btn2:function(index,layero){
//								            //按钮2的回调
//								          },cancel:function(){
//								            //右上关闭的回调
//								          }
//								      	})
//									}
//	
//	
//								};
							})
						}
						
						//监听单元格编辑
						table.on('edit(table100)', function(obj){
						    var value = obj.value //得到修改后的值
						    ,data = obj.data //得到所在行所有键值
						    console.log(data)
						    ,field = obj.field; //得到字段
						    AjaxPostFn('system/commoditdetails/updatebyid',JSON.stringify(data) , function(jsonData) {
						    	console.log(jsonData)
								if(jsonData.htmlState.status == 200) {
									layer.msg("修改成功");
									
								}
							})
		//				    layer.msg('[ID: '+ data.id +'] ' + field + ' 字段更改为：'+ value);
					 	});
					})
				</script>
			</div>
			<!-- 概述 end-->
		</div>
	</body>

</html>